Limiting the Rows Returned by a Select Statement

The following example shows how to use a Command object to limit the number of rows returned by the Oracle server.

NOTE: The example requires the emp table (see "Sample Tables for Oracle"). The Oracle database in this example does not require the Database connection string option.

SequeLinkConnection  DBConn; 
DBConn = new SequeLinkConnection("host=baleen;Port=19996;User ID=test01; 
                                  Password=test01"); 
SequeLinkDataAdapter myDataAdapter = new SequeLinkDataAdapter(); 
SequeLinkCommand  DBCmd = new SequeLinkCommand("SELECT * FROM EMP",DBConn); 
myDataAdapter.SelectCommand = DBCmd; 
DataSet   myDataSet = new DataSet(); 
try  
{ 
    DBConn.Open(); 
    // Set the RowSetSize on the Command object to limit the number  
    // of rows returned 
    DBCmd.RowSetSize = 10; 
    myDataAdapter.SelectCommand = DBCmd; 
    myDataAdapter.Fill(myDataSet); 
    // Normally, emp contains 14 rows. 
    // But with RowSetSize set to 10, the Command object 
    // will limit the result set to 10 rows. 
    MessageBox.Show(Convert.ToString(myDataSet.Tables["Table"].Rows.Count)); 
} 
catch (Exception ex)  
{ 
    // Display any exceptions in a messagebox 
    MessageBox.Show (ex.Message); 
} 
// Close the connection 
DBConn.Close();